﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Imageo.bintje;
using System.Web.UI.HtmlControls;
using System.Runtime.Serialization;
using System.Net;
using System.Threading;
using log4net;

namespace Imageo.ui
{
    public partial class TrailDelete : System.Web.UI.Page
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        int trailId;
        bool CanEdit;
        bool EditMode;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ///////////////////////////
                // Check that the trail I is valid
                string strTrailId = Request.QueryString["trailid"];

                if (!int.TryParse(strTrailId, out trailId))
                {
                    Response.Redirect("~/UI/ErrorGeneric.aspx");
                }

                bintje.imageoSession currentSession = Session["BintjeSession"] as imageoSession;

                if (currentSession == null)
                {
                    // It is not possible to create a trail without a session
                    //Response.Redirect("~/UI/ErrorLoginFirst.aspx");
                    throw new Exception("aarrrrgg");
                }

                ServiceAPI service = new ServiceAPI();
                trailRequest request = new trailRequest();
                request.trailId = trailId;
                request.session = currentSession;
                statusResponse response;

                // Load the trail or create an empty trail
                if (trailId != 0)
                {
                    if (log.IsErrorEnabled) log.Debug("Calling: service.deleteTrail(request)");
                    response = ServiceHelper.HandleBintjeErrors(this, service.deleteTrail(request));
                }
            }
            catch (ThreadAbortException) { }
            catch (Exception exc)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(exc.Source + " - " + exc.Message);
                }
                Response.Redirect("~/UI/ErrorGeneric.aspx");
            }
        }
    }
}
